10029. Corona2020
Ziya
suspects that he has contracted coronavirus. In connection with this, he is
conducting research on his DNA, and as a result of the
calculations, he finds out that three different numbers a, b and c are related to his
DNA. Ziya believes that if by substituting + or - instead of the signs
(<>) into the expression a <> b <> c, he can obtain the number 2020, then he has not contracted
the coronavirus. Otherwise, if it is impossible to do so, then he has
contracted it. Help Ziya determine if he has contracted the coronavirus.
Input. Three integers a, b, and c (1 ≤ a, b, c ≤ 108)
are given.
Output. If Ziya has not contracted the virus, print
the expression a <> b <> c, which
results in 2020. Otherwise, print the word CORONA. When outputting the
expression, there should be no spaces between the numbers and operators.
Sample
input 1 |
Sample
output 1 |
2019 2020 2021 |
2019-2020+2021 |
|
|
Sample
input 2 |
Sample
output 2 |
2019 2020 2022 |
CORONA |
full search
Iterate over all possible signs between the
numbers a, b, and c. If the value of
the resulting expression is equal to 2020, then print the expression. Otherwise,
print the word CORONA.
Read the input data.
scanf("%d %d %d",
&a, &b, &c);
Iterate over all possible signs between the numbers. Depending on the result,
print the answer.
if (a + b + c == 2020) printf("%d+%d+%d", a, b,
c); else
if (a + b - c == 2020) printf("%d+%d-%d", a, b,
c); else
if (a - b + c == 2020) printf("%d-%d+%d", a, b,
c); else
if (a - b - c == 2020) printf("%d-%d-%d", a, b,
c); else
printf("CORONA\n");
Python realization
Read the input data.
a, b, c = map(int, input().split())
Iterate over all possible signs between the numbers. Depending on the result,
print the answer.
if a + b + c == 2020:
print(f"{a}+{b}+{c}")
elif a + b - c == 2020:
print(f"{a}+{b}-{c}")
elif a - b + c == 2020:
print(f"{a}-{b}+{c}")
elif a - b - c == 2020:
print(f"{a}-{b}-{c}")
else:
print("CORONA")